package com.gxa.modules.service.operationsservice.impl;

import com.gxa.common.R;
import com.gxa.modules.mapper.operationsmapper.PublicResourceMapper;
import com.gxa.modules.pojo.Build;
import com.gxa.modules.pojo.PublicResources;
import com.gxa.modules.service.operationsservice.GongGongZiYuanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class GongGongZiYuanServiceImpl implements GongGongZiYuanService {

    @Autowired
    private PublicResourceMapper publicResourceMapper;
    R r = new R();
    @Override
    public R selectGongGongZiYuan(String publicName, int page, int limit) {
        int index = (page-1)*limit;
        List<PublicResources> publicResources = publicResourceMapper.selectGongGongZiYuan(publicName,index,limit);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(publicResources);
        r.setCount(publicResourceMapper.selectGongGongZiYuanCount(publicName));
        return r;
    }

    @Override
    public R delGongGongZiYuan(String ids) {
        String[] split = ids.split(",");
        int i = publicResourceMapper.delGongGongZiYuan(split);
        if (i > 0){
            r.setCode(200);
            r.setMsg("删除成功");
        }else {
            r.setCode(500);
            r.setMsg("删除失败");
        }
        return r;
    }

    @Override
    public R insertGongGongZiYuan(PublicResources publicResources) {
        int i = publicResourceMapper.insertGongGongZiYuan(publicResources);
        if (i > 0){
            r.setCode(200);
            r.setMsg("添加成功");
        }else {
            r.setCode(500);
            r.setMsg("添加失败");
        }
        return r;
    }

    @Override
    public R updGongGongZiYuan(PublicResources publicResources) {
        int i = publicResourceMapper.updGongGongZiYuan(publicResources);
        if (i > 0){
            r.setCode(200);
            r.setMsg("修改成功");
        }else {
            r.setCode(500);
            r.setMsg("修改失败");
        }
        return r;
    }

    @Override
    public R selectLouYu() {
        List<Build> builds = publicResourceMapper.selectLouYu();
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(builds);
//        r.setCount(publicResourceMapper.selectGongGongZiYuanCount());
        return r;
    }
}

